
function connectUsrByMqtt(Mqtt,options) {

   // const Mqtt = require('mqtt');
    /*
    const mqttParam = {
        server: 'tcp://cloudmqtt.usr.cn:1883',
        options: {
            username: 'xuefeng',
            password: '466c20e5be1c3e921f60359f94501c29',
            clientId: '00021839000000000003'
        },
        topic: '$00021839000000000001'
    };
    */
    const mqttParam = options;
    const mqttClient = Mqtt.connect(mqttParam.server, mqttParam.options);

    mqttClient.on('connect', function () {
        console.log('**Success-Connecting to broker   :' + mqttParam.server);
        console.log('**Connected Client id is         :' + mqttParam.options.clientId);

        mqttClient.subscribe(mqttParam.topic);
        console.log('**Subscribed to topic            : ' + mqttParam.topic)

     // mqttClient.publish(mqttParam.topic, 'Message from Baidu IoT demo');
     // console.log('**Success-MQTT messasge published.');
    });



    mqttClient.on('error', function (error) {
        console.error(error);
    });

    mqttClient.on('message', function (topic, data) {
        console.log('MQTT message received: ' + data);
        return 'MQTT message received: ' + data
        if (data.toString() === 'exit') process.exit();
    });
}

module.exports = {
    connectUsrByMqtt,
}